package com.ls.lserp.modules.reportforms.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ls.lserp.common.service.CrudService;
import com.ls.lserp.common.utils.ResourcesUtil;
import com.ls.lserp.modules.reportforms.dao.ReportformsStyleDao;
import com.ls.lserp.modules.reportforms.entity.ReportformsStyleEntity;
import com.ls.lserp.modules.sys.utils.DesignoptionUtils;
@Service
@Transactional(readOnly = false)
public class ReportformsStyleService extends CrudService<ReportformsStyleDao,ReportformsStyleEntity>{

	@Autowired
    private ReportformsStyleDao reportformsStyleDao;
	
	/**
	 * 获取数据报表信息
	 * @param reportformsStyleEntity
	 * @return List<ReportformsStyleEntity>
	 */
	public List<ReportformsStyleEntity> reportformsStyleInfo(ReportformsStyleEntity reportformsStyleEntity) {
		//
		List<ReportformsStyleEntity> rList = new ArrayList<>();
		//临时数据报表实体
		ReportformsStyleEntity reportformsTemp = new ReportformsStyleEntity();
		String[] itemList = ResourcesUtil.getConfig("styleItemData").split(",");
		if (itemList != null && itemList.length > 0) {
			for (int i = 0; i < itemList.length; i++) {
				reportformsTemp.setStartDate(reportformsStyleEntity.getStartDate());
				reportformsTemp.setEndDate(reportformsStyleEntity.getEndDate());
				//数据来源
				reportformsTemp.setDataSource(DesignoptionUtils.getDesignoptionName(itemList[i]));
				reportformsStyleEntity.setDataSource(itemList[i]);
				//设置数据类型为荷兰定制
				reportformsStyleEntity.setDataType(ResourcesUtil.getConfig("order_type-type_10"));
				if ("4SIZE".equals(itemList[i])) {
					reportformsTemp.setReportformsList(reportformsStyleDao.findSizeDataInfo(reportformsStyleEntity));
				}else {
					//领子
					if ("4SCO".equals(itemList[i])) {
						reportformsStyleEntity.setDataLimitNum(Long.parseLong(ResourcesUtil.getConfig("Limit10")));
						//袖头
					}else if ("4SCU".equals(itemList[i])) {
						reportformsStyleEntity.setDataLimitNum(Long.parseLong(ResourcesUtil.getConfig("Limit5")));
					}
					reportformsTemp.setReportformsList(reportformsStyleDao.findItemDataInfo(reportformsStyleEntity));
				}
				rList.add(reportformsTemp);
				reportformsTemp = new ReportformsStyleEntity();
			}
		}
		return rList;
	}
	/**
	 * 导出数据报表信息
	 * @param reportformsStyleEntity
	 * @return List<ReportformsStyleEntity>
	 */
	public List<ReportformsStyleEntity> exportReportforms(ReportformsStyleEntity reportformsStyleEntity) {
		//
		List<ReportformsStyleEntity> rList = new ArrayList<>();
		//临时数据报表实体
		ReportformsStyleEntity reportformsTemp = new ReportformsStyleEntity();
		String[] itemList = ResourcesUtil.getConfig("styleItemData").split(",");
		if (itemList != null && itemList.length > 0) {
			for (int i = 0; i < itemList.length; i++) {
				//数据来源
				reportformsTemp.setDataSource(DesignoptionUtils.getDesignoptionName(itemList[i]));
				reportformsStyleEntity.setDataSource(itemList[i]);
				//设置数据类型为荷兰定制
				reportformsStyleEntity.setDataType(ResourcesUtil.getConfig("order_type-type_10"));
				if ("4SIZE".equals(itemList[i])) {
					rList.addAll(reportformsStyleDao.exportSizeDataList(reportformsStyleEntity));
				}else {
					//领子
					if ("4SCO".equals(itemList[i])) {
						reportformsStyleEntity.setDataLimitNum(Long.parseLong(ResourcesUtil.getConfig("Limit10")));
						//袖头
					}else if ("4SCU".equals(itemList[i])) {
						reportformsStyleEntity.setDataLimitNum(Long.parseLong(ResourcesUtil.getConfig("Limit5")));
					}
					rList.addAll(reportformsStyleDao.exportItemDataList(reportformsStyleEntity));
				}
				reportformsTemp = new ReportformsStyleEntity();
			}
		}
		return rList;
	}
}
